package com.idefav.Controllers;

import com.idefav.Service.HelloService;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * Created by wzs on 2017/7/22.
 */
@RestController
@RequestMapping("/hello")
public class HelloController {

    private final Logger logger = Logger.getLogger(getClass());

    @Autowired
    private HelloService helloService;

    @Autowired
    private DiscoveryClient discoveryClient;

    @RequestMapping("/say/{test}")
    public String say(@PathVariable("test") String test) {
        ServiceInstance serviceInstance = discoveryClient.getLocalServiceInstance();
        logger.info("/hello,host:" + serviceInstance.getHost() +",port:"+serviceInstance.getPort()+ ",service_id:" + serviceInstance.getServiceId());
        return helloService.say(test);
    }
}
